﻿@model  NB.MGJ.Model.AntiFleeing_IOWarehouse
@{
    Layout = null;
}
@*编辑出库信息*@
<script src="~/Scripts/MGJJS/FleeGoods/CommonBox.js"></script>
<script src="~/Scripts/MGJJS/FleeGoods/FormCode.js"></script>
<style>
    .form-horizontal .form-group {
        margin-bottom: 15px;
    }
</style>
<form class="form-horizontal" id="form" onkeydown="if(event.keyCode==13){return false;}">
    @Html.HiddenFor(m => m.Id)
    @if (Model.ProductID != "0")
    {
        <div class="form-group">
            <label class="col-sm-2 control-label">产品名称：</label>
            <div class="col-sm-10">
                @Html.TextBoxFor(p => p.ProductName, new { @class = "form-control", @placeholder = "产品名称", maxlength = 64, disabled = "disabled" })
            </div>
        </div>
    }
    else
    {
        <div class="form-group">
            <label class="col-sm-2 control-label">产品名称：</label>
            <div class="col-sm-10">
                @Html.DropDownList("ProductID", null, new { @class = "form-control", @onchange = "OnChange()" })
            </div>
        </div>
    }

   
    @if (Model.WarehouseId != 0)
    {
        <div class="form-group">
            <label class="col-sm-2 control-label">出货仓库：</label>
            <div class="col-sm-10">
                @Html.DropDownList("WarehouseId", null, new { @class = "form-control", disabled = "disabled" })

            </div>
        </div>
    }
    else
    {
        <div class="form-group">
            <label class="col-sm-2 control-label">出货仓库：</label>
            <div class="col-sm-10">
                @Html.DropDownList("WarehouseId", null, new { @class = "form-control", onchange = "OnChange()" })

            </div>
        </div>
    }


    <div class="form-group">
        <label class="col-sm-2 control-label">经销商片区：</label>
        <div class="col-sm-10">

            @Html.DropDownList("SaleAreaId", null, new { @class = "form-control", id = "SaleAreaId" })

        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">经销商：</label>
        <div class="col-sm-10">
            <select id="Distributor" class="form-control" name="Distributor" data-live-search="true" data-actions-box="true" onchange="OnChange()"></select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">出库数量：</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(p => p.Num, new { @class = "form-control", @placeholder = "出库数量", maxlength = 64, disabled = "disabled" })
        </div>
    </div>

    <div class="form-group" style="display:flex;align-items:center">
        <label class="col-sm-2 control-label">查看物流码：</label>
        <div class="col-sm-10">
            <a href="#" onclick="$.MGJ.CommonBox.Dialog_CommonBox('@Model.FilePath')">查看物流码</a>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">货品仓位：</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(p => p.Location, new { @class = "form-control", @placeholder = "货品仓位", maxlength = 64, })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">物流公司：</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(p => p.ExpressCompany, new { @class = "form-control", @placeholder = "物流公司", maxlength = 64, })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">物流单号：</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(p => p.ExpressCode, new { @class = "form-control", @placeholder = "物流单号", maxlength = 64, })
        </div>
    </div>
    <div class="form-group">

        <label class="col-sm-2 control-label">备注：</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(p => p.Remark, new { @class = "form-control", @placeholder = "备注", maxlength = 64, })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">出库编码：</label>
        <div class="col-sm-10" >
            @*@Html.TextBoxFor(p => p.FormCode, new { @class = "form-control", @placeholder = "入库编码", maxlength = 64, disabled = "disabled" })*@
            <input type="text" class="form-control" placeholder="出库编码" name="FormCode" id="FormCode" value="@Model.FormCode" readonly>
            <div style="color:red">入库编码：片区编号-经销商编号-产品编号-当前时间</div>
        </div>
    </div>
</form>
<script>
   
    Distributor(@Model.Distributor);
    $("#SaleAreaId").change(function () {
        Distributor(@Model.Distributor);
    });
    function Distributor(disId) {
        $("#Distributor").empty();
        $.ajax({
            type: "POST",
            url: "/FleeGoods/SelDistributorList",
            data: { SaleAreaId: $("#SaleAreaId").val(), disId: disId },
            success: function (data) {
                data[0].Selected=true;
                $.each(data, function (i, item) {
                    if (item["Selected"] == true) {
                        $("<option></option>").val(item["Value"]).text(item["Text"]).attr("selected", "selected").appendTo($("#Distributor"))
                    }
                    else $("<option></option>").val(item["Value"]).text(item["Text"]).appendTo($("#Distributor"));
                })
                OnChange();
            }
        });
       
    }

    $('#form').bootstrapValidator({
        fields: {
            Distributor: {
                validators: {
                    notEmpty: {
                        message: '经销商不能为空'
                    },
                }
            },
            SaleAreaId: {
                validators: {
                    notEmpty: {
                        message: '经销商片区不能为空'
                    },
                }
            },
            WarehouseId: {
                validators: {
                    notEmpty: {
                        message: '出货仓库不能为空'
                    },
                }
            },
            ProductName: {
                validators: {
                    notEmpty: {
                        message: '出货仓库不能为空'
                    },
                }
            },
            ProductID: {
                validators: {
                    notEmpty: {
                        message: '出货仓库不能为空'
                    },
                }
            },
        }
    });
    function OnChange(aa) {
        var formCode = '@Model.FormCode';  
        if (formCode.replace(/(^s*)|(s*$)/g, "").length ==0) {
            var proId=@Model.ProductID;
            if (proId == 0) {
                proId = $("#ProductID").val();
            }
            var areaId = $("#SaleAreaId").val();
            var disId = $("#Distributor").val()==null||$("#Distributor").val()==""?0:$("#Distributor").val();
            $.MGJ.CommonBox.FromCode(areaId+'-'+disId+'-'+proId)
        }
    }
</script>
